import {
  reqGetBaseCategoryList,
  reqGetBannerListData,
  reqGetFloorListData,
} from "@/api/index"

const state = {
  // 三级导航数据
  categoryList: [],
  // 轮播图数据
  bannerList: [],
  //楼层数据
  floorList: [],
}

const actions = {
  // 获取三级导航数据
  async getCategoryList({ commit }) {
    const result = await reqGetBaseCategoryList()
    if (result.code === 200) {
      // console.log(result.data)
      commit("SAVE_CATEGOR_LIST", result)
    } else {
      console.log(result.message)
    }
  },

  // 获取轮播图数据
  async getBannerListData({ commit }) {
    const result = await reqGetBannerListData()
    if (result.code === 200) {
      // console.log("成功--->", result)
      commit("BANNER_LIST_DATA", result)
    } else {
      console.log(result.message)
    }
  },

  // 获取楼层数据
  async getFloorListData({ commit }) {
    const result = await reqGetFloorListData()
    // console.log("楼层--->", result)
    if (result.code === 200) {
      commit("FLOOR_LIST_DATA", result)
    } else {
      console.log(result.message)
    }
  },
}

const mutations = {
  // 保存三级导航数据
  SAVE_CATEGOR_LIST(state, payload) {
    state.categoryList = payload.data
  },
  // 保存轮播图数据
  BANNER_LIST_DATA(state, payload) {
    // console.log("保存数据-->", payload.data)
    state.bannerList = payload.data
  },
  // 保存楼层数据
  FLOOR_LIST_DATA(state, payload) {
    // console.log("保存楼层-->", payload.data)
    state.floorList = payload.data
  },
}

const getters = {}

export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters,
}
